package com.cskaoyan.javase.io._2char._0introduction;

import org.junit.Test;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;

/**
 * 字符流的引入
 * @since 09:58
 * @author wuguidong@cskaoyan.onaliyun.com
 */
public class Demo {
    @Test
    public void test() {
        // 文本文件中的英文字母,阿拉伯数字一个字符,占一个字节
        String s1 = "a";
        byte[] bs1 = s1.getBytes();
        // 文本文件中"我"汉字,一个字符占用三个字节
        String s2 = "我";
        byte[] bs2 = s2.getBytes();
        System.out.println(Arrays.toString(bs1));
        System.out.println(Arrays.toString(bs2));
    }

    // 用字节输入流读取文本文件中的汉字
    @Test
    public void test2() throws IOException {
        FileInputStream in = new FileInputStream("a.txt");
        byte[] buf = new byte[4];
        int readCount = in.read(buf);
        in.close();
        System.out.println(readCount);
        System.out.println(new String(buf, 0, readCount));
    }
}
